#include <iostream>
#include <queue>
#include <string>

using namespace std;

// 定义二叉树节点结构
struct TreeNode {
    char val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(char x) : val(x), left(NULL), right(NULL) {}
};

// 创建二叉树
TreeNode* createTree() {
    string input;
    getline(cin, input);
    if (input == "#") return NULL;

    queue<TreeNode*> q;
    TreeNode* root = new TreeNode(input[0]);
    q.push(root);

    int i = 2; // 从第二个字符开始
    while (!q.empty() && i < input.size()) {
        TreeNode* current = q.front();
        q.pop();

        if (i < input.size() && input[i] != '0') {
            current->left = new TreeNode(input[i]);
            q.push(current->left);
        }
        i += 2;

        if (i < input.size() && input[i] != '0') {
            current->right = new TreeNode(input[i]);
            q.push(current->right);
        }
        i += 2;
    }

    return root;
}

// 统计叶子结点数
int countLeaves(TreeNode* node) {
    if (!node) return 0;
    if (!node->left && !node->right) return 1;
    return countLeaves(node->left) + countLeaves(node->right);
}

int main() {
    TreeNode* root = createTree();
    int leafCount = countLeaves(root);
    cout << leafCount << endl;

    return 0;
}